#ifndef FA71675A_0D83_4800_9CD3_C376657FB4AC
#define FA71675A_0D83_4800_9CD3_C376657FB4AC


#endif /* FA71675A_0D83_4800_9CD3_C376657FB4AC */

// 模拟C++11简单线程库
#include <iostream>
#include <string>
using namespace std;

static int num = 1;

typedef void(*callback_t)();

class Thread
{   
public:
    Thread(callback_t cb)
        :cb_(cb), tid_(0), name_(""), start_timestamp_(0), isrunning_(false)
    {}

    static void* Routine(void* args)
    {
        Thread* tp = static_cast<Thread*>(args);
        tp->Entery();
        return nullptr;
    }

    void Run()
    {
        name_ = "thread-" + to_string(num++);
        start_timestamp_ = time(nullptr);
        isrunning_ = true;
        pthread_create(&tid_, nullptr, Routine, this);
    }

    void Join()
    {
        pthread_join(tid_, nullptr);
        isrunning_ = false;
    }

    string GetName()    // 获取线程名字
    {
        return name_;
    }

    uint64_t GetStartTimeStamp()    // 获取时间戳
    {
        return start_timestamp_;
    }

    bool IsRunning()    // 判断该线程是否正在运行
    {
        return isrunning_;
    }

    void Entery()
    {
        cb_();
    }

    ~Thread()
    {}
private:
    pthread_t tid_;
    string name_;
    uint64_t start_timestamp_;
    bool isrunning_;
    
    callback_t cb_;
};


